var app = new Vue({
  el: '#search',
  data () {
    return {
      imglist: null,
      dialogShow: false,
      errMsg: ""
    }
  },
  created() {
    this.getAddress()
  },
  methods: {
    // 获取5家超市图片
    getImgData () {
      Axios.post('/goods/goods/supermarket.do', {}).then(res => {
        if (res.respCode==="S") {
          this.imglist = res.data          
        }    
      }).catch(err => {
        console.error(err)
      })
    },
    // 获取默认收货地址
    getAddress () {
      let accessToken = getCookie('accessToken')
      if (accessToken) {
        Axios.post('/user/address/getDefaultReceiveAddress.do', {}).then(res => {
          if (res.respCode === "S") {            
            this.getImgData()
          } else {
            this.errMsg = "您没有设置默认收货地址！"
            this.dialogShow = true
          }
        }).catch(err => {
          console.error(err)
        })
      }
    },
    // 选择收货地址
    clickAddress () {
      window.location.href = "../my/my_shouhuo.html"
    },
    // 点击按品牌搜索
    clickBrand () {
      window.location.href = "./search_pinpai.html"
    },
    // 点击按商品名搜索
    clickGoodsname () {
      window.location.href = "./search_shangpin.html"
    },
    // 点击按分类搜索
    clickCategory () {
      window.location.href = "./searchCategory.html"
    },
    // 点击自定义下单
    clickCustom () {
      window.location.href = "./custom_Order.html"
    },
    // 取消设置默认收货地址
    btnCancel () {
      window.location.href = "../index.html"
    },
    // 设置默认收货地址
    btnOk () {
      window.location.href = "../my/my_shouhuo.html"
    }
  }
})